<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
//$this->model('model')->check_custom();
$this->model('model')->check_worker('',true);
//注册电商客会员
//$_SESSION['openid']='cosen';
$item=pdo_get('jy_scrm_worker',array('merchid'=>$_SESSION['onemerchid'],'userid'=>$_SESSION['openid'],'uniacid'=>$_SESSION['uniacid']));
if($_SESSION['container']=='wxwork' && !$item['avatar']){
	$return['show_wxworkmember']=2;
}
$item['mymembernum']=pdo_count('jy_scrm_member',array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'follow_user_userid'=>$_SESSION['openid']));
$item['myqunnum']=pdo_count('jy_scrm_qun',array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'owner'=>$_SESSION['openid']));
$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
$item['daymembernum']=pdo_count('jy_scrm_member',array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'follow_user_userid'=>$_SESSION['openid'],'createtime >'=>$daytime));
$item['daygenjinnum']=pdo_count('jy_scrm_worker_linelog',array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'workerid'=>$item['id'],'createtime >'=>$daytime));
$item['genjinnum']=pdo_count('jy_scrm_worker_linelog',array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'workerid'=>$item['id']));
if($_SESSION['openid']=='cosen'){
	$item['mymembernum']=1802;
	$item['daymembernum']=18;
	$item['daygenjinnum']=16;
	$item['dayliushinum']=2;
	$item['genjinnum']=1081;
}
$link_time[0]=0;
$link_time[1]=$daytime-3*24*3600;
$link_time[2]=$daytime-7*24*3600;
$link_time[3]=$daytime-15*24*3600;
$link_time[4]=$daytime-30*24*3600;
$link_time[5]=$daytime-90*24*3600;
$link_time[6]=$daytime-180*24*3600;
$link_times=$this->link_times;
$statuslist=array();
$buystatus=$this->user_buystatus;
foreach($buystatus as $k=>$v){
	$statuslist[$k]['title']=$v;
	$statuslist[$k]['num']=pdo_count('jy_scrm_member',array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'follow_user_userid'=>$_SESSION['openid'],'buystatus'=>$k));
	foreach($link_times as $lk=>$lv){
		$statuslist[$k]['list'][$lk]['title']=$lv;
		$statuslist[$k]['list'][$lk]['num']=pdo_count('jy_scrm_member',array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'follow_user_userid'=>$_SESSION['openid'],'buystatus'=>$k,'link_time <='=>$link_time[$lk]));
	}
}
$return['item']=$item;
$return['statuslist']=$statuslist;
$wxwork_app=pdo_get('core_account_wxwork_app',array('id'=>$_SESSION['wxworkapp_id'],'uniacid'=>$_SESSION['uniacid']));
$wxwork_app['corpid']=pdo_getcolumn('core_account_wxwork',array('id'=>$wxwork_app['wxwork_id'],'uniacid'=>$_SESSION['uniacid']),'appid');
$backurl=urlencode(custom_url('jy_merchscrm/oauth2/upworker/app_id='.$_SESSION['wxworkapp_id'],true));
$state='upworker';
$auth_url='https://open.weixin.qq.com/connect/oauth2/authorize?appid='.$wxwork_app['corpid'].'&redirect_uri='.$backurl.'&response_type=code&scope=snsapi_privateinfo&agentid='.$wxwork_app['appid'].'&state='.$state.'#wechat_redirect';
$return['auth_url']=$auth_url;
$return['buystatus']=0;
set_html('title','会员中心');
exi($return);	
?>